import 'package:flutter/material.dart';
import 'package:flutterdemo/pages/address.dart';
import 'package:flutterdemo/pages/chat_info.dart';
import 'package:flutterdemo/pages/collect.dart';
import 'package:flutterdemo/pages/history.dart';
import 'package:flutterdemo/pages/member.dart';
import 'package:flutterdemo/pages/order.dart';
import 'package:flutterdemo/pages/personal_change.dart';
import 'package:flutterdemo/pages/real_name.dart';
import 'package:flutterdemo/pages/setting.dart';
import '../pages/tabs/tab.dart';
import '../pages/shop_info.dart';
import '../pages/login.dart';
import '../pages/reg.dart';
import '../pages/search.dart';

final routes = {
  // 首页
  '/': (context) => Tabs(),

  // 商品详情
  'chatInfo': (context) => ChatInfo(),

  // 登录
  'login': (context) => Login(),

  // 商品详情
  'shopInfo': (context) => ShopInfo(),

  // 注册
  'reg': (context) => Reg(),

  // 设置
  'setting': (context) => Setting(),

  //收藏 
  'collect': (context) => Collect(),
  
  // 浏览历史
  'history': (context) => History(),

  // 收货地址
  'address': (context) => Address(),

  // 会员中心
  'member': (context) => Member(),

  // 实名认证
  'realName': (context) => RealName(),

  // 订单管理
  'order': (context) => Order(),

  // 搜索
  'search': (context) => Search(),
  
  // 个人信息修改
  'personalChange': (context) => PersonalChange(),
};

bool login = false;

//固定写法 可直接复制使用
// ignore: missing_return, prefer_function_declarations_over_variables
var onGenerateRoute = (RouteSettings settings) {
  // 统一处理
  String? name = settings.name;
  // if(!login){
  //   name = "login";
  //   login = true;
  // }
  

  final Function pageContentBuilder = routes[name] as Function;
  // ignore: unnecessary_null_comparison
  if (pageContentBuilder != null) {
    if (settings.arguments != null) {
      final Route route = MaterialPageRoute(builder: (context) {
        return pageContentBuilder(context, arguments: settings.arguments);
      });
      return route;
    } else {
      final Route route = MaterialPageRoute(builder: (context) {
        return pageContentBuilder(context);
      });
      return route;
    }
  }
};
